import React, { useEffect, useState } from 'react';
import DescriptionsCondition from '@/components/DescriptionsCondition';
import { connect } from 'umi';
import { Intention, source, stage } from '@/common/contact';
const PointDetail = (props) => {
  const { dispatch, visible = {}, showTictok = false } = props;
  const { detail = {}, show } = visible;
  const { id, } = detail
  const [data, setData] = useState({})
  const { douyinTaskName = '', douyinComment = '', recommendUsername = '', shareName, shareType } = data
  
  useEffect(() => {
    if (show) {
      dispatch({
        type: 'subscriber/fetchUserDetail',
        payload: {
          organizationUserId: id,
        },
        callback: (e) => {
          setData(e)
        },
      });
    }
  }, [id])
  const formItems = [
    {
      label: '抖音昵称',
      name: 'douyinUserName',
    },
    {
      label: '微信昵称',
      name: 'wechatUsername',
    },
    {
      label: '姓名',
      name: 'username',
    },

    {
      label: '头像 ',
      type: 'upload',
      name: 'profile',
    },
    {
      label: '性别 ',
      name: 'gender',
      render: (e) => {
        return ['无', '男', '女'][e];
      },
    },
    {
      label: '手机',
      name: 'mobile',
    },
    {
      label: '生日',
      name: 'birthday',
    },
    {
      label: '身份证',
      name: 'idCard',
    },
    {
      label: '学校',
      name: 'school',
    },
    {
      label: '专业',
      name: 'specialty',
    },
    {
      label: '考试年份',
      name: 'examYear',
    },
    {
      label: '用户标签',
      name: 'tags',
    },
    {
      label: '用户描述',
      name: 'userDesc',
    },
    {
      label: '用户得分',
      name: 'score',
    },
    {
      label: '来源',
      name: 'source',
      render: (e) => {
        return source[e];
      },
    },
    {
      label: '分享人名字',
      show: shareName,
      name: 'shareName',
    },
    {
      label: '分享人类型',
      show: shareType,
      name: 'shareType',
      render: (e) => {
        return { user: '用户', admin: '员工/代理' }[e];
      },
    },
    {
      label: '抖音任务名称',
      name: 'douyinTaskName',
      show: douyinTaskName && douyinTaskName.length > 0 && showTictok
    },
    {
      label: '抖音评论',
      name: 'douyinComment',
      show: douyinComment && douyinComment.length > 0 && showTictok
    },
    {
      label: '推荐人姓名',
      name: 'recommendUsername',
      show: data.source === 'user' || data.source === 'oldUser'
    },
    {
      label: '备案人',
      name: 'addAdminName',
    },
    {
      label: '备案时间',
      name: 'addTime',
    },
    {
      label: '当前阶段 ',
      name: 'stage',
      render: (e) => {
        return stage[e];
      },
    },
    {
      label: '意向方向',
      name: 'intentionDirectionNames',
    },
    {
      label: '意向课程',
      name: 'intentionCourseNames',
    },

    {
      label: '已购课程',
      name: 'buyFaceToFaceGoods',
    },

    {
      label: '最后跟进时间 ',
      name: 'lastFollowUpTime',
    },
    {
      label: '最后跟进人 ',
      name: 'lastFollowUpAdminName',
    },
    {
      label: '最后跟进人头像 ',
      name: 'lastFollowUpAdminProfile',
      type: 'upload',
    },
    {
      label: '当前状态',
      name: 'invalidStatus',
      render: (e) => {
        return e === '1' ? '有效' : '无效'
      }
    },
    {
      label: '无效原因',
      name: 'invalidReason',
    },
    {
      label: '是否锁定',
      name: 'lockFlag',
    },
    // {
    //   label: '目标课程',
    //   name: 'targetCourseNames',
    // },
    {
      title: '意向度',
      dataIndex: 'intention',
      render: (e) => {
        return Intention[e];
      },
    },
    {
      label: '预计报名时间',
      name: 'expectedRegistrationDate',
    },

  ];

  return (
    <DescriptionsCondition formItems={formItems.filter(item => {
      const { show = true } = item
      return show
    })} initialValues={data}></DescriptionsCondition>
  );
};
export default connect(({ subscriber, loading }) => ({
  loading: loading.effects['subscriber/fetchUserDetail'],
}))(PointDetail);;
